﻿using System;
using System.IO;

namespace ClientAPI
{
    class Settings
    {
        private static Settings _instance = null;
        int BUFFERSIZE;
        int FILEBUFFERSIZE;
        string HOST;
        int COMMANDPORT;
        int FILEPORT;
        int CHATPORT;
        string FOLDERLOCATION;

        private Settings()
        {
        }

        public static Settings Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new Settings();
                    return _instance;
                }
                else
                    return _instance;
            }
        }

        public void ImportConfigurations()
        {
            TextReader reader = new StreamReader("settings.ini");

            string importString = reader.ReadToEnd();
            //System.Diagnostics.Debug.WriteLine(importString);

            string[] importArray = importString.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            for (int i = 0; i < importArray.Length; i++)
            {
                string[] tempArray = importArray[i].Split('=');
                string tempName = tempArray[0];

                if (tempArray[0] == "BUFFERSIZE")
                    Instance.BUFFERSIZE = Convert.ToInt16(tempArray[1]);
                else if (tempArray[0] == "FILEBUFFERSIZE")
                    Instance.FILEBUFFERSIZE = Convert.ToInt16(tempArray[1]);
                else if (tempArray[0] == "HOST")
                    Instance.HOST = tempArray[1];
                else if (tempArray[0] == "COMMANDPORT")
                    Instance.COMMANDPORT = Convert.ToInt16(tempArray[1]);
                else if (tempArray[0] == "FILEPORT")
                    Instance.FILEPORT = Convert.ToInt16(tempArray[1]);
                else if (tempArray[0] == "CHATPORT")
                    Instance.CHATPORT = Convert.ToInt16(tempArray[1]);
                else if (tempArray[0] == "FOLDERLOCATION")
                    Instance.FOLDERLOCATION = tempArray[1];
                else
                {
                    System.Diagnostics.Debug.WriteLine("errror importing settings");
                    break;
                }
            }
        }

        public int GetBufferSize()
        {
            return BUFFERSIZE;
        }

        public int GetFileBufferSize()
        {
            return BUFFERSIZE;
        }

        public string GetHost()
        {
            return HOST;
        }

        public int GetCommandPort()
        {
            return COMMANDPORT;
        }

        public int GetFilePort()
        {
            return FILEPORT;
        }

        public int GetChatPort()
        {
            return CHATPORT;
        }

        public string GetFolderLocation()
        {
            return FOLDERLOCATION;
        }

    }
}

